package cn.sq.musicserver.config;

import cn.sq.musicserver.plug.model.qqmusicapi.constant.QQMusicApiConstant;
import cn.sq.musicserver.plug.model.wpmusicapi.constants.WPMusicApiConstantKG;
import cn.sq.musicserver.plug.model.wpmusicapi.constants.WPMusicApiConstantKW;
import cn.sq.musicserver.plug.model.wpmusicapi.constants.WPMusicApiConstantQQ;
import cn.sq.musicserver.set.entity.SqSet;
import cn.sq.musicserver.set.service.impl.SqSetServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * User: SQ
 * Date: 2020/12/14
 * Time: 15:05
 * Description: 项目启动时初始化部分参数
 */
@Configuration
@Slf4j
public class Init implements ApplicationRunner {

    @Autowired
    SqSetServiceImpl sqSetService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        //下载路径
        SQConstant.SYSTEM_DOWNLOAD_DIR = sqSetService.getOne(new QueryWrapper<SqSet>().eq("SetName", "SystemDownloadDir")).getSetVlaue();
        //缓存路径
        SQConstant.SYSTEM_TEMPDOWNLOAD_DIR = sqSetService.getOne(new QueryWrapper<SqSet>().eq("SetName", "SystemTempDownloadDir")).getSetVlaue();
        SQConstant.SYSTEM_IMAGE_DIR = sqSetService.getOne(new QueryWrapper<SqSet>().eq("SetName", "SystemImageDir")).getSetVlaue();
        //qq音乐插件参数
        QQMusicApiConstant.BASE_URL = sqSetService.getOne(new QueryWrapper<SqSet>().eq("SetName", "QQMusicBasePath")).getSetVlaue();
        QQMusicApiConstant.SEARCH=QQMusicApiConstant.BASE_URL+"/search";
        QQMusicApiConstant.DOWNLOAD= QQMusicApiConstant.BASE_URL+"/song/url";
        QQMusicApiConstant.ALBUM= QQMusicApiConstant.BASE_URL+"/album";
        QQMusicApiConstant.LYRIC= QQMusicApiConstant.BASE_URL+"/lyric";
        String WPMusicApi = sqSetService.getOne(new QueryWrapper<SqSet>().eq("SetName", "WPMusicBasePath")).getSetVlaue();
        WPMusicApiConstantQQ.BASE_URL= WPMusicApi+"/v1/qq";
        WPMusicApiConstantQQ.DOWNLOAD= WPMusicApiConstantQQ.BASE_URL+"/song";
        WPMusicApiConstantQQ.SEARCH=WPMusicApiConstantQQ.BASE_URL+"/search";
        WPMusicApiConstantQQ.LYRIC=WPMusicApiConstantQQ.BASE_URL+"/lyric";

        WPMusicApiConstantKW.BASE_URL= WPMusicApi+"/v1/kuwo";
        WPMusicApiConstantKW.DOWNLOAD= WPMusicApiConstantKW.BASE_URL+"/song";
        WPMusicApiConstantKW.SEARCH=WPMusicApiConstantKW.BASE_URL+"/search";
        WPMusicApiConstantKW.LYRIC=WPMusicApiConstantKW.BASE_URL+"/lyric";

        WPMusicApiConstantKG.BASE_URL= WPMusicApi+"/v1/kugou";
        WPMusicApiConstantKG.DOWNLOAD= WPMusicApiConstantKG.BASE_URL+"/song";
        WPMusicApiConstantKG.SEARCH=WPMusicApiConstantKG.BASE_URL+"/search";
        WPMusicApiConstantKG.LYRIC= WPMusicApiConstantKG.BASE_URL+"/song";



        log.debug("启动成功");
    }

}
